
//
// 110407 - AH - Created.
// 110527 - AH - (Garage) Java doc.
//

package org.soekrat.engine.forest;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *   {@link TreeVisitor} that finds all leafs.
 * </p>
 * @author Arne Halvorsen (AH)
 */
public final class LeafFinderTreeVisitor implements TreeVisitor 
{
  private final List<Tree> m_leafs=new ArrayList<Tree>();
  
  /**
   * <p>
   *   Constructor.
   * </p>
   */
  public LeafFinderTreeVisitor(){}

  @Override
  public void visit(Tree tree){ if (tree.isLeaf()) m_leafs.add(tree); }
  
  /**
   * <p>
   *   Gets found leafs after a traversal.
   * </p>
   * @return Leafs.
   */
  public Tree[] getLeafs(){ return m_leafs.toArray(Tree.E_ARRAY); }
 
}
